package com.lxj.controller;

import com.lxj.domain.User;
import com.lxj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("/log")
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Map<String ,Object> login(User user) {
        Jedis jedis = new Jedis();
        String code = jedis.get("loginCode");
        Map<String ,Object> result = userService.login(user);
        if (code.equalsIgnoreCase(user.getCode())){
            return result;
        }else {
            result.put("result",0);
            return result;
        }
    }
    @PostMapping("/getName")
    public Map<String ,String> getName(String token){
        Map<String ,String> map = new HashMap<>();
        String result =  userService.getName(token);
        map.put("result",result);
        return map;
    }
}
